package org.lzfto.flink.demo.business.flinkTest.base.file;

import org.lzfto.flink.demo.business.flinkTest.base.BasicTable;

/**
 * excel作为源的逻辑表，目前只支持读取，不支持Sink
 * @author lzfto
 * @created 2025年6月4日 16:58:30
 */
public class ExcelSourceTable extends BasicTable {

    private String path;
    private String fileName;
    private Boolean deleteAfterRead;
    private Integer startRow;
    private String  extension;
    private String  extensionHyphen;
    

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    public Boolean getDeleteAfterRead() {
        return deleteAfterRead;
    }

    public void setDeleteAfterRead(Boolean deleteAfterRead) {
        this.deleteAfterRead = deleteAfterRead;
    }

    public Integer getStartRow() {
        return startRow;
    }

    public void setStartRow(Integer startRow) {
        this.startRow = startRow;
    }

    public String getExtension() {
		return extension;
	}

	public void setExtension(String extension) {
		this.extension = extension;
	}

	public String getExtensionHyphen() {
		return extensionHyphen;
	}

	public void setExtensionHyphen(String extensionHyphen) {
		this.extensionHyphen = extensionHyphen;
	}
	
	/**
	 * 设置文件后缀，如果不调用，则默认是xlsx
	 * @param ext 后缀，非空
	 * @return
	 */
	public ExcelSourceTable withExtension(String ext) {
		this.extension=ext;
		return this;
	}
	
	/**
	 * 设置FileName和后缀前文件分隔符号之前的连字符
	 * @param hyphen 连字符
	 * @return
	 */
	public ExcelSourceTable withExtensionHyphen(String hyphen) {
		this.extensionHyphen=hyphen;
		return this;
	}

	@Override
    public String build() throws Exception {
    	if (this.getConnector()==null) {
			throw new Exception("请先设置连接器connector属性");
		}
		//标准SQL;
		String result = """
				with(
				  'connector'='%s',
				  'path' = '%s',
				  'file-name' = '%s',
				  'extension'='%s',
				  'extension-hyphen'='%s',
				  'start-row' = '%d',
				  'delete-after-read' = '%b'				  
				)
				""".formatted(
						this.getConnector(),
						this.getPath(),
						this.getFileName(),
						this.extension,
						this.extensionHyphen,
						this.getStartRow(),
						this.getDeleteAfterRead()						
						);
		return result;
    }
}
